// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import App from './App';
import router from './router';
import http from './http';
import appConfig from './utils/bases.js';
import Toast from './components/Toast/index.js'
import store from './vuex'
// import { Lazyload } from 'vant';

// Vue.use(Lazyload);

Vue.use(ElementUI);

Vue.use(http);

Vue.use(Toast);

Vue.config.productionTip = false;

Vue.prototype.appConfig = appConfig;

router.beforeEach((to, from, next) => {
  if(to.matched.some( m => m.meta.auth)) {
    // 对路由进行验证
    if(localStorage.getItem("userInfo")) { // 已经登陆
      next(); // 正常跳转到你设置好的页面
    } else {
      // 未登录则跳转到登陆界面，query:{ Rurl: to.fullPath}表示把当前路由信息传递过去方便登录后跳转回来；
      next({path:'/Login', query:{/*Rurl: to.fullPath*/}});
    }
  } else {
    if(localStorage.getItem("userInfo")) { // 已经登陆
      next(from.path);
    } else {
      // 未登录则跳转到登陆界面，query:{ Rurl: to.fullPath}表示把当前路由信息传递过去方便登录后跳转回来；
      next();
    }
  }
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  store,
  router,
  components: { App },
  template: '<App/>'
})
